package com.lc.hongtai.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lc.hongtai.MyApplication;
import com.lc.hongtai.R;
import com.lc.hongtai.activity.InvestmentActivity;
import com.lc.hongtai.conn.JsonInvest;
import com.lc.hongtai.progress.SaundProgressBar;
import com.lc.hongtai.view.ProgressBar;

import java.text.NumberFormat;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2/22/2016.
 */
public class MyInvestlistAdapter_New extends RecyclerView.Adapter<MyInvestlistAdapter_New.ViewHolder> {

    public final static int TYPE_ONE = 0;
    public final static int TYPE_TWO = 1;


    private Context context;
    public final static int INVESTMODE = 1;//投资
    public final static int MANAGEFINANCESMODE = 2;//理财
    public final static int BONDMODE = 3;//债卷
    private int isInvest = 0;
    private List<JsonInvest.Info.ListContent> list;


    private SaundProgressBar mPbar;
    public static int progress = 0;

    private boolean loadMore = false;

    public MyInvestlistAdapter_New(Context context, List<JsonInvest.Info.ListContent> list, int isInvest) {
        this.context = context;
        this.list = list;
        this.isInvest = isInvest;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        // each data item is just a string in this case
        @Bind(R.id.tv_rate)
        TextView tvRate;
        @Bind(R.id.tv_time)
        TextView tvTime;

        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_sumMoney)
        TextView tvSumMoney;


        public String str;
        public int a;

        @Bind(R.id.progress_horizontal)
        ProgressBar horizontalNumProgressBar;
        @Bind(R.id.tv_progress)
        TextView tv_progress;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

   /*     View view = LayoutInflater.from(context).inflate(R.layout.item_investlist, null);
        ViewHolder vh = new ViewHolder(view);
        return vh;*/

      /*  View view = null;
        RecyclerView.ViewHolder holder = null;
        switch (viewType) {
            case TYPE_ONE:
                view = MyApplication.scaleScreenHelper.loadView((ViewGroup)LayoutInflater.from(context).inflate(R.layout.item_investlist, parent, false));
                holder = new ViewHolderOne(view);
                break;
            case TYPE_TWO:
                view = LayoutInflater.from(mContext).inflate(android.R.layout.simple_list_item_1, parent, false);
                holder = new ViewHolderTwo(view);
                break;
        }*/
        View view = MyApplication.scaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(context).inflate(R.layout.item_investlist, parent, false));
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tvName.setText(list.get(position).borrow_name);
        NumberFormat nfNumber = NumberFormat.getNumberInstance();
        holder.tvRate.setText(list.get(position).borrow_interest_rate + "%");
        holder.tvTime.setText(list.get(position).borrow_duration + list.get(position).borrow_duration_cn);


        holder.tvSumMoney.setText(list.get(position).need);

        holder.horizontalNumProgressBar.setProgress2(20);
        holder.tv_progress.setText("20.00");

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("id", list.get(position).id);
                intent.setClass(context, InvestmentActivity.class);
                context.startActivity(intent);

            }
        });
    }
    @Override
    public int getItemCount() {
        return list.size();
    }
    @Override
    public int getItemViewType(int position) {
        // return super.getItemViewType(position);

        if (list.size() > 3) {
            if (!loadMore) {
                if (position == 3) {
                    return TYPE_ONE;
                }

            }
        }
        return TYPE_TWO;
    }
}
